# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=terminalpp
pkgver=0.8.4
pkgrel=0
pkgdesc="Minimalist, fast, cross-platform terminal emulator"
url="https://terminalpp.com/"
# armhf, armv7, x86: fails to build
arch="all !armhf !armv7 !x86"
license="MIT"
makedepends="
	cmake
	freetype-dev
	libx11-dev
	libxcursor-dev
	libxft-dev
	mesa-dev
	samurai
	"
subpackages="
	$pkgname-ropen
	tpp-bypass
	"
source="https://github.com/terminalpp/terminalpp/archive/v$pkgver/terminalpp-$pkgver.tar.gz"
builddir="$srcdir/terminalpp-$pkgver"

build() {
	local cmake_opts="
		-G Ninja
		-DCMAKE_INSTALL_PREFIX=/usr
		-DSTAMP_ARGS=--no-override
		"
	[ "$CBUILD" = "$CHOST" ] || cmake_opts="
		$cmake_opts
		-DCMAKE_SYSTEM_NAME=Linux
		-DCMAKE_HOST_SYSTEM_NAME=Linux
		"

	cmake -B build \
		-DCMAKE_BUILD_TYPE=Release \
		-DINSTALL=terminalpp \
		$cmake_opts
	cmake --build build --target terminalpp
	cmake --build build --target tests

	cmake -B build-ropen \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DINSTALL=ropen \
		$cmake_opts
	cmake --build build-ropen --target ropen

	cmake -B build-bypass \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DINSTALL=tpp-bypass \
		$cmake_opts
	cmake --build build-bypass --target tpp-bypass
}

check() {
	cd build
	./tests/tests
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

ropen() {
	pkgdesc="Utility to open remote files in Terminal++"

	cd "$builddir"
	DESTDIR="$subpkgdir" cmake --install build-ropen
}

bypass() {
	pkgdesc="Utility to create a linux pseudoconsole inside WSL to bypass ConPTY"

	cd "$builddir"
	DESTDIR="$subpkgdir" cmake --install build-bypass
}

sha512sums="
498755b11e7e14d9aec4450e4f5a9446cb591fd73672ad306d2b292814b3bdbb10b0e6d6248f849b30f531a92f419881c7e59dcfa85117155c0e45aabb8943ad  terminalpp-0.8.4.tar.gz
"
